package com.zcxk.web.handler;

import com.zcxk.common.SingleResponse;
import com.zcxk.config.AuthToken;
import com.zcxk.constant.Constants;
import com.zcxk.dao.dataobject.User;
import com.zcxk.dto.UserDTO;
import com.zcxk.service.UserService;
import com.zcxk.service.UserServiceImpl;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.web.RoutingContext;

import java.util.Objects;

/**
 * @author wangping
 * @date 2023-07-28 21:56
 */
public class LoginHandler implements Handler<RoutingContext> {
  @Override
  public void handle(RoutingContext ctx) {
    JsonObject requestBody = ctx.body().asJsonObject();
    String username = requestBody.getString("username");
    String password = requestBody.getString("password");
    User user = new User();
    user.setUsername(username);
    user.setPassword(password);
    UserService userService = new UserServiceImpl();
    UserDTO userDTO = userService.login(user);
    ctx.json(SingleResponse.of(userDTO));
  }
}
